#!/usr/bin/python
# -*- coding: cp1250 -*-

import re
import string
import sys
import os
import pepe.p_txt.bigtxt as bt
    
def csv_cmix2(inpFile, outFile, colFrom, colTo, cDelimiter):
    """
    csv_cmix2 in.csv out.csv 1 2 ';'
    csv_cmix2(   inpFile='in.csv'
               , outFile='out.csv'
               , colFrom=1
               , colTo=2
               , cDelimiter=';')
    """
    outFile = open(outFile, "w")
    lineString = ''
    colFrom = int(colFrom)
    colTo = int(colTo)
    if colFrom == colTo: print "No change (colFrom = colTo)"
    else:
        for line in bt.lines(inpFile):
            line = re.sub("\n","",line)
            columns = string.split(line, cDelimiter)
            if colFrom > colTo:
                    columns.insert(colTo-1, columns[colFrom-1])
                    del columns[colFrom]
            if colFrom < colTo:
                    columns.insert(colTo, columns[colFrom-1])
                    del columns[colFrom-1]
            lineString = cDelimiter.join(columns) + "\n"
            outFile.write(lineString) 

if __name__ == "__main__":
    """ """
    if len(sys.argv) == 6:
        print string.join(sys.argv[1:],',')
        csv_cmix2(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])
    else:
        print csv_cmix2.__doc__
        #os.system('pause')
